﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

namespace sdamarketing
{
    public class ReturnDataSet
    {
        public static DataSet ReturSet(string sql)
        {
            DataSet dataSet = new DataSet();
            
            SqlConnection connection = ConnectionMenager.GetConnection();
            SqlCommand command = new SqlCommand(sql, connection);
            command.CommandType = CommandType.Text;

            SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
            dataAdapter.Fill(dataSet, "DataSet");
                            // DataSet -> E vsusnost ime na promenlivata (Imeto na Tabelata koja ja vrakame)

            connection.Close();
            return dataSet;
        }
        public static bool FindSomthing(string sql)
        {
            SqlConnection connection = ConnectionMenager.GetConnection();

            SqlCommand command = new SqlCommand(sql, connection);
            command.CommandType = CommandType.Text;

            SqlDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);

            int temp;
            reader.Read();
            bool exsist;
            try
            {
                temp = int.Parse(reader[0].ToString());
                exsist = true;
            }
            catch (Exception)
            {
                exsist = false;
            }

            connection.Close();
            return exsist;
        }
    }
}
